package com.data.service

import com.data.annotation.NoargAnnotation
import com.data.annotation.OpenAnnotation
import com.data.bean.IndexAdmin
import com.data.bean.IndexCase
import com.data.bean.Theme
import com.data.bean.ThemeClass
import com.data.dao.IndexDao
import com.data.entity.ThemeAdminEntity
import com.data.entity.ThemePage
import com.data.util.FinalStringUtils
import com.data.util.ImageLookUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.stereotype.Service

@Controller
@OpenAnnotation
@NoargAnnotation
@Service
class IndexService {
    @Autowired
    private var indexDao: IndexDao? = null


    fun showImageService(image: String, type: Int): ByteArray? {
        val path = when (type) {
            0 -> FinalStringUtils.INDEXIMAGEPAHT//banner图
            1 -> FinalStringUtils.INDEXCASEIMAGEPAHT//案例图片
            2 -> FinalStringUtils.THEME//主题图片
            else -> FinalStringUtils.IMAGEDEFAULT//默认图
        }
        return ImageLookUtils.readImage(path, image)
    }

    fun indexBannerService(type: Int): List<IndexAdmin> = indexDao!!.indexBannerDao(type)

    fun indexCaseService(): List<IndexCase> = indexDao!!.indexCaseDao()

    fun caseClassService(): List<ThemeClass> = indexDao!!.caseClassDao()

    fun themeCaseService(start: Int, end: Int, cid: String): List<ThemeAdminEntity> {
        val themePage = ThemePage(start, end, cid)

        return indexDao!!.themeCaseDao(themePage)
    }

    fun claxxNumService(cid: String): Int = indexDao!!.claxxNumDao(cid).size


}